<template>
    <van-popup v-if="isShow" v-model="isShow" round position="bottom">
        <van-picker class="lwt-picker" title="选择一个权重表" show-toolbar :columns="columns" @confirm="onConfirm" @cancel="onCancel"
            @change="onChange"></van-picker>
    </van-popup>
</template>

<script>
import { Toast, Notify } from 'vant';
import { CalcServer, SearchServer } from '../../server/servers';
let vm;

export default {
    name: 'LoadWeights',

    props: {
        isLoadWeightsViewShow: Boolean,
    },

    created() {
        vm = this;
    },

    computed: {
        isShow: {
            get() {
                return this.isLoadWeightsViewShow;
            },
            set() {
                this.selectedResult = null;
                return this.$emit("close");
            }
        }
    },

    watch: {
        isShow(val, old) {
            if (val) {
                this.queryAll();
            }
        }
    },

    filters: {

    },

    data() {
        return {
            columnIds: [],
            columns: [],

            sidebarActiveKey: 0,
            selectedResult: null,

            results: [],
        }
    },

    methods: {
        queryAll() {
            // this.results = CalcServer.queryAllWeightsName();
            console.log("queryAll");
            let list = CalcServer.queryAllWeightsName();
            console.log("LoadWeights.queryAll", list);

            this.columnIds = [];
            this.columns = [];
            list.some(e => {
                this.columnIds.push(e.id);
                this.columns.push(e.name);
            })

            console.log("LoadWeights.vue", "queryAll结果", list, this.columnIds, this.columns);
        },

        queryId(id) {

        },

        onConfirm(value, index) {
            console.log("LoadWeights.onConfirm", value, index);
            this.$emit('confirm', this.columnIds[index]);
        },

        onCancel(picker, value, index) {
            this.isShow = false;
        },

        onChange() {

        }
    }
}
</script>

<style scoped >

.lwt-picker{
    z-index:200000;
}

.lwt-picker /deep/ .van-picker__title{
    cursor: default;
}

.lwt-picker /deep/ .van-picker-column__item--selected{
    background-color: rgba(172, 171, 171, 0.393);
}

.lwt-picker  /deep/ li{
    cursor: pointer;
}

</style>